<?php

return [
    'module' => [
        'name' => 'user_coupon',
        'title' => '用户优惠券',
        'table' => 'user_coupons',
    ],
    
    'fields' => [
        'id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '用户优惠券ID',
            'unsigned' => true,
            'nullable' => false,
            'primary' => true,
            'auto_increment' => true,
            'required' => true,
        ],
        'user_id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '用户ID',
            'unsigned' => true,
            'nullable' => false,
            'required' => true,
            'index' => true,
        ],
        'coupon_id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '优惠券ID',
            'unsigned' => true,
            'nullable' => false,
            'required' => true,
            'index' => true,
        ],
        'order_id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '使用订单ID',
            'unsigned' => true,
            'nullable' => false,
            'default' => 0,
        ],
        'status' => [
            'type' => 'tinyint',
            'length' => 4,
            'comment' => '状态：0未使用，1已使用，2已过期',
            'nullable' => false,
            'required' => true,
            'default' => 0,
            'index' => true,
        ],
        'used_time' => [
            'type' => 'timestamp',
            'comment' => '使用时间',
            'nullable' => true,
        ],
        'created_at' => [
            'type' => 'timestamp',
            'comment' => '创建时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true,
        ],
        'updated_at' => [
            'type' => 'timestamp',
            'comment' => '更新时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true,
            'extra' => 'ON UPDATE CURRENT_TIMESTAMP',
        ],
    ],
    
    'relations' => [
        'user' => [
            'type' => 'belongsTo',
            'model' => 'User',
            'foreign_key' => 'user_id',
        ],
        'coupon' => [
            'type' => 'belongsTo',
            'model' => 'Coupon',
            'foreign_key' => 'coupon_id',
        ],
        'order' => [
            'type' => 'belongsTo',
            'model' => 'Order',
            'foreign_key' => 'order_id',
        ],
    ],
    
    'queries' => [
        'user_id' => ['=', '?'],
        'coupon_id' => ['=', '?'],
        'order_id' => ['=', '?'],
        'status' => ['=', '?'],
        'created_at' => ['between', '?,?'],
        'used_time' => ['between', '?,?'],
    ],
]; 